/**   
 * @Title: LotteryRecordListAdapterModify.java 
 * @Package com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord 
 * @Description: 重写adpter,用于1.4.1我的彩票购彩记录界面方案 
 * @author: City Jiangsy@500wan.com   
 * @date: 2012-1-10 下午3:01:44  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.cheetah.view.personal.lotteryrecord;

import java.util.ArrayList;
import java.util.Hashtable;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.esun.cheetah.R;
import com.esun.cheetah.config.Config;
import com.esun.cheetah.config.Language;
import com.esun.util.log.EDebug;

/**
 * 
 * @Package 
 *          com.esun.cheetah.view.personal.lotteryrecord.LotteryRecordListAdapterModify
 * @ClassName: LotteryRecordListAdapterModify
 * @Description: TODO(重写adpter,用于1.4.1我的彩票购彩记录界面方案)
 * @author 孔祥攀 <br/>
 * @date 2012-4-13 下午2:43:38
 * 
 */
public class LotteryRecordListAdapterModify extends BaseAdapter {
	private LayoutInflater listInflater;
	// private ArrayList<View> recordListView = new ArrayList<View>();
	private ArrayList<Hashtable<String, String>> list = new ArrayList<Hashtable<String, String>>();

	private TextView tvlotnames;
	private TextView tvPlayName;
	private TextView tvTime;
	private TextView tvPayMoney;
	// private TextView tvIssucState;
	private TextView tvWinMoney;
	private TextView tvLotteryState;
	// private TextView tvLotName;

	private ImageView imgArrow;
//	private ImageView imgLotName;

	private static final String IS_TITLE = "istitle";
	private static final String YES = "yes";
//	private static final String EXPECT = "expect";
	private static final String PLAY_NAME = "playname";
	private static final String PLAY_ID = "playid";
	private static final String ADD_DATE = "adddate";
	private static final String PAY_MONEY = "paymoney";
	private static final String ADD_TIME = "addtime";
//	private static final String ISSUC = "issuc";
//	private static final String STATE = "state";
	private static final String GET_MONEY = "getmoney";
	private static final String LOT_ID = "lotid";
//	private static final String LOTNAMES = "lotnames";
	private static final String ISJPRIZE = "isjprize";
	private static final String ISPRIZE = "isprize";


//	private String[] strsLotId = { Config.SHUANGSEQIU, Config.DALETOU,
//			Config.SHIYIXUANWU, Config.JINGCAIZUQIU,
//			Config.BEIJINGZUQIUDANCHANG, Config.FUCAI3D, Config.SHENGFUCAI,
//			Config.RENXUANJIU, Config.QILECAI, Config.QIXINGCAI,
//			Config.ERSHIERXUANWU, Config.SHISHICAI, Config.PAILIESAN,
//			Config.PAILIEWU, Config.JINGCAILANQIU, Config.LIUCHANGBANQUAN,
//			Config.SICHANGJINQIU, Config.KUAILESHIFEN };
//	private int[] intsSrc = {
//			R.drawable.img_default_boughtcenter_doubleball_45x45,
//			R.drawable.img_default_boughtcenter_lotto_45x45,
//			R.drawable.img_default_boughtcenter_11pick5_45x45,
//			R.drawable.img_default_boughtcenter_jcf_45x45,
//			R.drawable.img_default_boughtcenter_bdspf_45x45,
//			R.drawable.img_default_boughtcenter_3d_45x45,
//			R.drawable.img_default_boughtcenter_football_45x45,
//			R.drawable.img_default_boughtcenter_football9_45x45,
//			R.drawable.img_default_boughtcenter_7le_45x45,
//			R.drawable.img_default_boughtcenter_7star_45x45,
//			R.drawable.img_default_boughtcenter_22pick5_45x45,
//			R.drawable.img_default_boughtcenter_ssc_45x45,
//			R.drawable.img_default_boughtcenter_pl3_45x45,
//			R.drawable.img_default_boughtcenter_pl5_45x45,
//			R.drawable.img_default_boughtcenter_jcb_45x45,
//			R.drawable.img_default_boughtcenter_6cb_45x45,
//			R.drawable.img_default_boughtcenter_4c_45x45,
//			R.drawable.img_default_boughtcenter_10f_45x45 };

	public LotteryRecordListAdapterModify(Context context,
			ArrayList<Hashtable<String, String>> tempList,
			ArrayList<View> tempViewList) {
		this.listInflater = LayoutInflater.from(context);
		this.list = tempList;
		// this.recordListView = tempViewList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		// return recordListView.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		// if(recordListView.size() < position + 1){

		if (list.get(position).get(IS_TITLE).equals(YES)) {

			convertView = listInflater.inflate(
					R.layout.lotteryrecord_listtable_title, null);

			((TextView) convertView
					.findViewById(R.id.lotteryrecord_listtable_title_tv_lotteryDate))
					.setText(list.get(position).get(ADD_DATE));
			convertView.setEnabled(false);
			// recordListView.add(convertView);
			return convertView;

		} else {
			convertView = listInflater.inflate(
					R.layout.lotteryrecord_listtable_new, null);
			tvlotnames = (TextView) convertView
					.findViewById(R.id.lotteryrecord_table_new_tv_lotnames);
			tvPlayName = (TextView) convertView
					.findViewById(R.id.lotteryrecord_table_new_tv_playname);
			// tvLotName = (TextView)
			// convertView.findViewById(R.id.lotteryrecord_table_new_tv_lotName);
			tvPayMoney = (TextView) convertView
					.findViewById(R.id.lotteryrecord_table_new_tv_payMoney);
			tvTime = (TextView) convertView
					.findViewById(R.id.lotteryrecord_table_new_tv_lotteryTime);
			// tvIssucState = (TextView)
			// convertView.findViewById(R.id.lotteryrecord_table_new_tv_issuc);
			tvWinMoney = (TextView) convertView
					.findViewById(R.id.lotteryrecord_table_new_tv_getMoney);
			tvLotteryState = (TextView) convertView
					.findViewById(R.id.lotteryrecord_table_new_tv_lotteryState);
			imgArrow = (ImageView) convertView
					.findViewById(R.id.lotteryrecord_table_new_imageview_arrow);
			// imgLotName = (ImageView)
			// convertView.findViewById(R.id.lotteryrecord_table_new_img_lotName);

			/** modify 接口修改,不不需要再对任九单独处理 */
//			for (int i = 0; i < strsLotId.length; i++) {
//				EDebug.o(LotteryRecordListAdapterModify.this, "lot id is "
//						+ list.get(position).get(LOT_ID) + " now id is "
//						+ strsLotId[i]);
//				// if (list.get(position).get(LOT_ID).equals(strsLotId[i])) {
//				// imgLotName.setBackgroundResource(intsSrc[i]);
//				break;
//			}
		}

		// 判断是否可以查看详情
		if (list.get(position).get(LOT_ID).equals(Config.SHUANGSEQIU)
				|| list.get(position).get(LOT_ID).equals(Config.DALETOU)
				|| list.get(position).get(LOT_ID).equals(Config.SHIYIXUANWU)
				|| list.get(position).get(LOT_ID).equals(Config.JINGCAIZUQIU)
				|| list.get(position).get(LOT_ID)
						.equals(Config.BEIJINGZUQIUDANCHANG)
				|| list.get(position).get(LOT_ID).equals(Config.FUCAI3D)
				|| list.get(position).get(LOT_ID).equals(Config.NUM1)
				|| list.get(position).get(LOT_ID).equals("10000")) {
			if (LotteryRecordTotalAct.isDanTuo(list.get(position).get(PLAY_ID))) {
				imgArrow.setVisibility(View.INVISIBLE);
			}
		} else {
			imgArrow.setVisibility(View.INVISIBLE);
		}

		// 彩票标识
		// tvIssucState.setText("投注金额");
		tvlotnames.setText(list.get(position).get("lotname"));
		// tvLotName.setText(list.get(position).get(EXPECT) +
		// Language.POPLOTTERYTIP_QI);

		tvPlayName.setText(list.get(position).get(PLAY_NAME));
		tvPayMoney
				.setText("￥"
						+ list.get(position)
								.get(PAY_MONEY)
								.substring(
										0,
										list.get(position).get(PAY_MONEY)
												.indexOf('.') + 3));
		tvTime.setText(list.get(position).get(ADD_TIME));
		// 中将状态
		EDebug.o(
				LotteryRecordListAdapterModify.this,
				"list adapter lottery state =="
						+ list.get(position).get(ISJPRIZE));

		// if (list.get(position).get(ISSUC).equals(Config.NUM0)) {
		// tvLotteryState.setText(Language.POPLOTTERYTIP_NOTISSUC);
		// } else if (list.get(position).get(ISSUC).equals(Config.NUM1)) {
		// tvLotteryState.setText(Language.POPLOTTERYTIP_ISSUCYET);
		// }

		if (list.get(position).get(ISPRIZE).equals("0")) {
			tvLotteryState.setText(Language.POPLOTTERYTIP_NOTISSUC);
			tvWinMoney.setText("等待开奖中");
		} else if (list.get(position).get(GET_MONEY).equals("0.000000")) {
			tvLotteryState.setText(Language.POPLOTTERYTIP_ISSUCYET);
			tvWinMoney.setText("未中奖");
			tvWinMoney.setTextColor(Color.BLACK);
		} else if (list.get(position).get(ISPRIZE).equals("1")
				& !list.get(position).get(GET_MONEY).equals("0.000000")) {
			tvLotteryState.setText("已派奖");
			tvWinMoney.setText("￥"
					+ String.format("%.2f", Double.parseDouble(list.get(
							position).get(GET_MONEY))));
			tvWinMoney.setTextColor(Color.RED);
		}

		return convertView;
	}

}
